package Lambda;

import interclass.Student;

import javax.swing.*;
import java.util.Arrays;

public class LambdaDemo2
{
    public static void main(String[] args)
    {
       test1();
       test2();
    }

    public static void test1()
    {
        Student students[] = new Student[6];
        students[0] = new Student("张三", 38, 180, '男');
        students[1] = new Student("李四", 19, 170, '女');
        students[2] = new Student("王五", 26, 169, '男');
        students[3] = new Student("赵六", 28, 190, '女');
        students[4] = new Student("孙七", 24, 178, '男');
        students[5] = new Student("周八", 23, 175, '女');

        //按年龄排序
        //先打印看看
        for(int i = 0; i < students.length;i++)
        {
            Student s = students[i];
            System.out.println(s);
        }
        System.out.println("=========================================");
//        Arrays.sort(students, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        });

        Arrays.sort(students, ( o1,  o2) -> o1.getAge() - o2.getAge());

        for(int i = 0; i < students.length;i++)
        {
            Student s = students[i];
            System.out.println(s);
        }

    }

    public static void test2()
    {
        JFrame win = new JFrame("登录窗口");
        win.setSize(300,200);
        win.setLocationRelativeTo(null);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        win.add(panel);
        JButton btn = new JButton("登录");
        panel.add(btn);
        //java要求必须给按钮添加一个监听器对象，这样可以监听用户的点击操作。
        btn.addActionListener(( e)-> System.out.println("用户点击了登录按钮,登录成功"));

        win.setVisible(true);

    }

}
